/*
 * Albareth - an action roleplaying game.
 * Copyright (C) 2008 Jens Anuth
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 *   02110-1301, USA.
 * 
 * $Id: Spell.java 46 2008-05-15 18:09:39Z jens464 $
*/
package albareth.core.action;

import albareth.core.entity.Activatable;
import albareth.core.entity.AssetOwner;
import albareth.core.entity.Mobile;
import albareth.core.entity.Representable;
import albareth.frontend.Tile;

public abstract class Spell extends Action implements Activatable, Representable, Cloneable
{
    private String _shortDescription = null;
    private Tile _tile;
    
    protected int spellStrength = 1;
    private int _manaRequirement = 0;


    public Spell(String name, Tile tile)
    {
        super(name);
        _tile = tile;
    }
    
    public Object clone() throws CloneNotSupportedException
    {
        return super.clone();
    }

    
    public AssetOwner getOwner()
    {
        return getPerformer();
    }
    
    public int getAmount()
    {
        return 1;
    }

    public Tile getTile()
    {
        return _tile;
    }

    public void setTile(Tile tile)
    {
        _tile = tile;
    }

    public String getShortDescription()
    {
        return _shortDescription != null ? _shortDescription : getName();
    }

    public void setShortDescription(String shortDescription)
    {
        _shortDescription = shortDescription;
    }

    public int getManaRequirement()
    {
        return _manaRequirement;
    }

    public void setManaRequirement(int manaRequirement)
    {
        _manaRequirement = manaRequirement;
    }

    public int getSpellStrength()
    {
        return spellStrength;
    }

    public void setSpellStrength(int spellStrength)
    {
        this.spellStrength = spellStrength;
    }


    /*
    public boolean isAvailable()
    {
        return !isCasting() && (owner == null || owner.getMana() >= getManaRequirement());
    }
    */

    
    public boolean executeMobileTask(Mobile src)
    {
        boolean success = super.executeMobileTask(src); 

        if (success) {
            if (src != null) {
                src.consumeMana(_manaRequirement);
            }
        }

        return success;
    }

    public boolean activate(Mobile src)
    {
        return src.tryAction(this);
    }


    public boolean canActivate(Mobile user)
    {
        return user.getMana() >= getManaRequirement();
    }
    
    public boolean isActivatable()
    {
        return true;
    }
    
    protected boolean verifyConditions(Mobile src)
    {
        if (src.getMana() < getManaRequirement())
        {
            src.infoMsg("Not enough mana.");
            return false;
        }
        return super.verifyConditions(src);
    }
 

 

}
